package com.neusoft.my12306.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.neusoft.my12306.common.res.CommonResult;
import com.neusoft.my12306.entity.Orders;
import com.neusoft.my12306.entity.Passenger;
import com.neusoft.my12306.mapper.OrdersMapper;
import com.neusoft.my12306.service.IOrdersService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 葛彬
 * @since 2023-07-22
 */
@Service
public class OrdersServiceImpl extends ServiceImpl<OrdersMapper, Orders> implements IOrdersService {

    @Override
    public CommonResult addOrders(Orders orders) {
        orders.setOid(null);
        int i =  baseMapper.insert(orders);
        CommonResult  result =new CommonResult( orders.getOid());
        if (i <= 0 ){
            result.setNotModified();
        }

        return result;
    }

    @Override
    public CommonResult queryOrders(String name) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("paynm", name);

        List<Orders> lss = baseMapper.selectList(queryWrapper);
        CommonResult result = new CommonResult(lss);

        return result;
    }

    @Override
    public CommonResult payOrders(Integer oid, String paytime) {
        Orders od = baseMapper.selectById(oid);
        od.setState(1);
        od.setPaytime(paytime);
        int i = baseMapper.updateById(od);
        CommonResult result = new CommonResult(i);

        return result;
    }

    @Override
    public CommonResult queryMyTicket(String name) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("passnm", name);
        queryWrapper.eq("state", 1);
        List<Orders> lss = baseMapper.selectList(queryWrapper);
        CommonResult result = new CommonResult(lss);

        return result;
    }
}
